package com.moduleSys.cms.user;

import com.moduleSys.entity.system.User;
import com.moduleSys.userService.UserService;
import com.moduleSys.utils.json.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by czw on 2017/7/16 0016.
 */
@RestController
@RequestMapping(value = "/backstage")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/userManage/addUser",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult addUser(User user, @RequestParam(value = "roleIds[]",required=false) Long[] roleIds){
        userService.insertOrUpdate(user,roleIds);
        return  new JsonResult(1,null,null);
    }
    @RequestMapping(value = "/getUserPageList",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult getUserPageList(Integer pageSize,Integer currentPage,String username,Integer status){
        JsonResult jr = userService.selectByMap(pageSize, currentPage, username, status);
        return jr;
    }

    @RequestMapping(value = "/deleteUser",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult deleteUser(Long id){
        userService.deleteUser(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatus(1);
        jsonResult.setMsg("删除成功");
        return jsonResult;
    }

    @RequestMapping(value = "/userManage/deleteBatch",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult deleteBatch(String itemIds){
        userService.deleteBatch(itemIds);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatus(1);
        jsonResult.setMsg("删除成功");
        return jsonResult;
    }

    @RequestMapping(value = "/userManage/updateUser",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult updateUser(User user,@RequestParam(value = "roleIds[]",required=false) Long[] roleIds){
        userService.insertOrUpdate(user, roleIds);
        return  new JsonResult(1,null,null);
    }

    @RequestMapping(value = "/userManage/updateStatus",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult updateStatus(User user){
        userService.updateStatus(user);
        return  new JsonResult(1,null,null);
    }
}
